﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Plateformeur.Engine
{
    public class AnimatedGameObject : GameObject
    {
        Dictionary<string, Animation> mAnim;
        string mCurrentAnim = "";


        //-------------------------------
        
        public AnimatedGameObject(String pSpritePath, Vector2 pPositionInitiale, ContentManager pContent, Game pGame) : base(pSpritePath, pPositionInitiale, pContent, pGame)
        {
            mAnim = new Dictionary<string, Animation>();
            mCurrentAnim = "";
        }

        //--------------------------------
        public void AddAnimation(string pName, string pSpriteSheet, float pSpeed, int pNumberOfFrame)
        {
            mAnim.Add(pName, new Animation(this, pName, pSpriteSheet, pSpeed, pNumberOfFrame));
        }

        //------------------------------
        public void Play(string pAnimation)
        {
            if (pAnimation == mCurrentAnim)
                return;
            mCurrentAnim = pAnimation;
            mAnim[pAnimation].Play();
        }

        //---------------------------------------------

        public override void Update(GameTime pTime)
        {
            if (mCurrentAnim == "")
            {
                base.Update(pTime);
                return;
            }

            mAnim[mCurrentAnim].Update(pTime);

            base.Update(pTime);
        }

    }
}
